<template>
  <div>
    <div class="container">
      <!-- 表单 -->
      <el-form ref="form" :model="customer" :rules="rules" label-width="100px">
        <el-form-item label="客户名称" prop="name">
          <el-input v-model="customer.name"></el-input>
        </el-form-item>
        <el-form-item label="客户性别" prop="gender">
          <el-radio-group v-model="customer.gender">
            <el-radio label="MALE">男</el-radio>
            <el-radio label="FAMALE">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="客户地址" prop="address">
          <el-input v-model="customer.address"></el-input>
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input v-model.number="customer.phone"></el-input>
        </el-form-item>
        <el-form-item label="客户来源" prop="source">
          <el-select v-model="customer.source" placeholder="请输入客户来源">
            <el-option label="口碑" value="WORD_TO_MONTH">口碑</el-option>
            <el-option label="媒体" value="MEDIA">媒体</el-option>
            <el-option label="地推" value="PROMOTION">地推</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="客户状态" prop="state">
          <el-select v-model="customer.state" placeholder="请输入客户状态">
            <el-option label="未知" value="UNKNOWN">未知</el-option>
            <el-option label="有意向" value="INTENTIONAL">有意向</el-option>
            <el-option label="成交" value="DEALED">成交</el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-success" @click="handleSave"
            >请确认后提交
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    currentCust: {
      type: Object,
      required: true,
    },
  },
  data() {
    var validatePass = (rule, value, callback) => {
      if (!value) {
        return callback("请输入电话号码");
      } else {
        if (
          value !=
          "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])d{8}$"
        ) {
          return callback("请输入正确格式的手机号");
        }
      }
    };
    return {
      customer: this.currentCust,
      rules: {
        name: [{ required: true, message: "请输入客户姓名", trigger: "blur" }],
        phone: [{ validator: validatePass, trigger: "blur" }],
        address: [{ required: true, message: "请输入地址", trigger: "blur" }],
        lastFollowUpDate: [
          {
            type: "date",
            required: true,
            message: "请选择日期",
            trigger: "change",
          },
        ],
      },
    };
  },
  methods: {
    handleSave() {
      this.axios
        .put("/customer/update", this.customer)
        .then(() => {
          this.$message.success("数据更新成功");
        })
        .catch(() => {
          this.$message.error("数据更新失败");
        });
    },
    // handleDuplicate() {
    //   this.axios
    //     .get("/customer/check", { params: (nameOrPhone = this.nameOrPhone) })
    //     .then((resp) => {
    //       this.checkResult = resp.data;
    //     })
    //     .catch(() => {
    //       this.$message.error("检索失败");
    //     });
    // },
  },
};
</script>

<style scoped>
#app {
  margin-top: 100px;
}
#alert {
  margin-bottom: 30px;
}
</style>